import java.util.Scanner;

public class demo02 {
//    受伤的皇后
    public static int count=0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[][] arr=new int[n][n];
        int[] num=new int[n];
        dfs(arr,0,num,n);
        System.out.println(count);
    }
    public static void dfs(int[][] arr,int i,int[] num,int n){
        if(i==n){
            count++;
        }
        for (int k = 0; k < n; k++) {
            if(check(num,i,k)){
                num[i]=k;
                dfs(arr,i+1,num,n);
            }
        }

    }
    public static boolean check(int[] num,int i,int j){
        for (int k = 0; k < i; k++) {
            if(j==num[k]){
                return false;
            }
            if(i+j==num[k]+k){
                return false;
            }
            if((i-k==j-num[k])){
                return false;
            }
        }
        return true;
    }
}
